package com.changwu.cwbase.ui.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.changwu.cwbase.Constants;
import com.changwu.cwbase.R;
import com.changwu.cwbase.base.BasicDialog;


/**
 * @date:2017/2/16
 * @author: 魏寿明
 * @description:
 */

public class ModifyDialog extends BasicDialog implements View.OnClickListener {
    protected EditText et_content;// 确认按钮

    // dialog监听控件
    public ModifyDialog(Context context) {
        super(context);
        setContentView(R.layout.dialog_modify);
        getWindow().setLayout(ScreenUtils.getScreenWidth() * 8 / 10, ViewGroup.LayoutParams.WRAP_CONTENT);
//        getWindow().setGravity(Gravity.BOTTOM);
        this.context = context;
        init();
    }

    private void init() {
        title = findViewById(R.id.title);
        cancel = findViewById(R.id.cancel);
        submit = findViewById(R.id.submit);
        et_content = findViewById(R.id.et_content);
        submit.setOnClickListener(this);
        cancel.setOnClickListener(this);
    }

    public void setContent(String content) {
        et_content.setText(content);
        if (!TextUtils.isEmpty(content)) {
            et_content.setSelection(content.length());
        }
    }

    @Override
    public void onClick(View v) {
        if (listener != null) {
            switch (v.getId()) {
                case R.id.submit:
                    if (TextUtils.isEmpty(et_content.getText().toString().trim())) {
                        ToastUtils.showShort("请输入内容！");
                        return;
                    }
                    data.put(Constants.CONTENT, et_content.getText().toString().trim());
                    listener.submit(data);
                    dismiss();
                    break;
                case R.id.cancel:
                    dismiss();
                    break;
            }
        }
    }

}
